<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
	<%@ include file= "_meta.jsp"%>
	<link title="style1" rel="stylesheet" href="${pageContext.request.contextPath}/css/add_course.css" type="text/css" />
</head>
<body>

<%@ include file= "_menu.jsp"%>
<%@ include file= "_header.jsp"%>
<div class="form_content">
	<div id="test">

		<fieldset>
			<legend>录入专业</legend>

			<div class="form-row">
				<div class="field-label"><label for="major_name">专业名称</label>:</div>
				<div class="field-widget"><input name="major_name" id="major_name" class="required"
												 title="Enter your name"/></div>
			</div>

			<div class="form-row">
				<div class="field-label"><label for="major_id">专业号</label>:</div>
				<div class="field-widget"><input name="major_id" id="major_id" class="required validate-email"
												 title="Enter your name"/></div>
			</div>

			<div class="form-row">
				<div class="field-label"><label for="college">学院</label>:</div>
				<div class="field-widget"><select id="college" name="college" class="validate-selection"
												  title="Choose your department">
					<c:forEach var="college" items="${colleges}" varStatus="trow">
						<option value="${college.college_name}"
								college_id="${college.college_id}">${college.college_name}</option>
					</c:forEach>
				</select>
				</div>
			</div>

		</fieldset>

		<input type="submit" class="submit" value="提交"/> <input class="reset" type="button" value="重置"
																onclick="valid.reset(); return false"/>
	</div>
</div>
<%@ include file="_footer.jsp"%>
<script type="text/javascript">
    (function () {
        function sendReq() {
            var msg = {};
            var major_name = $('#major_name').val();
            var major_id = $('#major_id').val();
            var college_id = $('#college option:selected').attr('college_id');

            msg.major_name = major_name;
            msg.major_id = major_id;
            msg.college_id = college_id;

            console.log(msg);
            $.ajax({
                url: '${pageContext.request.contextPath}/admin/add_major',
                data: msg,
                dataType: "text",
                success: function (data) {
                    if (data == "success") {
                        alert("添加成功!")
                    }
                    else {
                        alert('添加失败!')
                    }
                }
            })
        }

        $('.submit').click(sendReq);
    })()
    /*function formCallback(result, form) {
        window.status = "valiation callback for form '" + form.id + "': result = " + result;
    }

    var valid = new Validation('test', {immediate : true, onFormValidate : formCallback});
    Validation.addAllThese([
        ['validate-password', '> 6 characters', {
            minLength : 7,
            notOneOf : ['password','PASSWORD','1234567','0123456'],
            notEqualToField : 'field1'
        }],
        ['validate-password-confirm', 'please try again.', {
            equalToField : 'field8'
        }]
    ]);*/
</script>
</body>
</html>